// 日志数据模型
class LogCacheModel {
  final int? id;
  final String level;
  final String message;
  final DateTime timestamp;
  final String? stackTrace;
  final String? tag;

  LogCacheModel({
    this.id,
    required this.level,
    required this.message,
    DateTime? timestamp,
    this.stackTrace,
    this.tag,
  }) : timestamp = timestamp ?? DateTime.now();

  // 转换为Map用于数据库操作
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'level': level,
      'message': message,
      'timestamp': timestamp.millisecondsSinceEpoch,
      'stack_trace': stackTrace,
      'tag': tag,
    };
  }

  // 从Map创建Log对象
  factory LogCacheModel.fromMap(Map<String, dynamic> map) {
    return LogCacheModel(
      id: map['id'],
      level: map['level'],
      message: map['message'],
      timestamp: DateTime.fromMillisecondsSinceEpoch(map['timestamp']),
      stackTrace: map['stack_trace'],
      tag: map['tag'],
    );
  }

  @override
  String toString() {
    return 'Log{id: $id, level: $level, message: $message, timestamp: $timestamp, stackTrace: $stackTrace}, tag: $tag}';
  }
}
